package scala.collection.mutable

import scala.collection.mutable

/**
 * 可变set集合
 */
object SetTest {
  def main(args: Array[String]): Unit = {
    //定义
    val set = mutable.Set(1, 2, 3)
    val set1 = mutable.Set(9, 39)
    println(set)
    //遍历
    set.foreach(println)

    //    2.集合添加元素
    set += 9 += 10
    set.add(11)
    println(set)

    val bool: Boolean = set1.add(8)
    println(bool)
    println(set1)

    val int1 = set1.+(9)
    println(int1)

    //    5.删除数据
    set -= 5
    println(set)
    set.remove(4)

    //合并两个set
    val set3 = set ++ set1
    //    println(set3)
    set1 ++= set
    println(set1)
    println("set=" + set)
    println("set1=" + set1)

    println("----------------------------")
    //set 并集
    println(set.union(set1))
    println(set.intersect(set1))

  }
}
